# 一个json对象
import abc
from typing import List, Generic, TypeVar


class JsonDTO(metaclass=abc.ABCMeta):
    @abc.abstractmethod
    def to_dict(self) -> dict:
        """
        conv todict
        :return:
        """
        pass


T = TypeVar('T')


class PagedContainer(Generic[T]):
    total_count: int = 0
    page: List[T] = []

    def __init__(self, param: dict = None):
        if param:
            if 'totalCount' in param:
                self.total_count = param.get('totalCount', 0)
            if 'page' in param:
                self.page = param.get('page', [])


class PagedResult(JsonDTO):
    content: List
    page: int
    page_size: int
    total: int
    total_page: int

    def __init__(self, param=None):
        if param is None:
            param = dict()
        self.content = param.get('content', [])
        self.page = param.get('page', 0)
        self.page_size = param.get('pageSize', 0)
        self.total = param.get('total', 0)
        self.total_page = param.get('totalPage', 0)

    def to_dict(self):
        return {
            'content': self.content,
            'page': self.page,
            'pageSize': self.page_size,
            'total': self.total,
            'totalPage': self.total_page
        }
